package org.javaqq.face.main.conn;

import java.util.Collection;
import java.util.Iterator;

import org.javaqq.face.main.orgmeta.MetaFactry;
import org.javaqq.face.resources.Info;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;

public class JavaQQRosterListner implements RosterListener {    
    // Ignored events    
    public void entriesAdded(Collection<String> addresses) {    
    	System.out.println("entriesAdded:"+addresses);
    	Iterator<String> iter=addresses.iterator();
    	while(iter.hasNext()){
    		String JID=iter.next();
    		MetaFactry.addContact(StringUtils.parseBareAddress(JID));
    	}
    }    
 
    public void entriesDeleted(Collection<String> addresses) {    
    	System.out.println("entriesDeleted:"+addresses);
    	Iterator<String> iter=addresses.iterator();
    	while(iter.hasNext()){
    		String JID=iter.next();
    		MetaFactry.removeContactGUI(StringUtils.parseBareAddress(JID));
    	}
    }    
 
    public void entriesUpdated(Collection<String> addresses) {    
    	System.out.println("entriesUpdated:"+addresses);
    }
 
    public void presenceChanged(Presence presence) {    
        System.out.println("Presence changed: "   
                + presence.getFrom() + " " + presence);    
        MetaFactry.changeContactState(presence);
    }    
}